package com.fd.wpx.sso.web.interceptor;

import com.fd.wpx.blog.pojo.SysUser;
import com.fd.wpx.sso.web.utils.RequestToBean;
import com.fd.wpx.sso.web.utils.ValidUser;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 注册拦截器，主要用于判断用户信息是否合法
 */
public class RegisterInterceptor extends HandlerInterceptorAdapter{
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        System.out.print("有用户注册，判断一下用户是否合法");
        SysUser user=RequestToBean.request2bean(request);
        boolean valid= ValidUser.validate(user);
        if(valid)
        {
            //用户合法继续运行
            return true;
        }else
        {
            //用户不合法，返回注册页面同时给用户提示，用户注册信息不合法
            response.sendRedirect("/page/register?error=error");
            return false;
        }

    }
}
